Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Namespace BMLERP
	Friend Class frmORD540
		Inherits System.Windows.Forms.Form

		Dim INVType(3) As Object
		Dim StaOrd(7) As Object
		Dim Per(3) As Object
		Dim OldEHODN As String
		Dim NewTrans As Byte
		Dim OldCurRate As Double
		Private Sub cboEHCCD_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboEHCCD.ClickEvent
			Dim RecCCI As ADODB.Recordset
			If eventArgs.area = 2 Then
				txtEHCCD.Text = cboEHCCD.CtlText
				cboEHCCD.Visible = False
				RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtEHCCD.Text & "' order by CIDTE DESC")
				If Not RecCCI.EOF Then
					txtEHCER.Text = RecCCI.Fields("CICCR").Value
				Else
					txtEHCER.Text = CStr(0)
				End If
			End If
		End Sub

		Private Sub cboEHCNO_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboEHCNO.ClickEvent
			If eventArgs.area = 2 Then
				txtEHCNO.Text = cboEHCNO.BoundText
				txtCMNME.Text = cboEHCNO.CtlText
				cboEHCNO.Visible = False
				txtEHSNO.Focus()
			End If
		End Sub


		Private Sub cboEHITP_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboEHITP.SelectedIndexChanged
			'    txtEHODN.SetFocus
		End Sub

		Private Sub cboEHSNO_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboEHSNO.ClickEvent
			If eventArgs.area = 2 Then
				txtEHSNO.Text = cboEHSNO.BoundText
				txtMMNME.Text = cboEHSNO.CtlText
				cboEHSNO.Visible = False
				txtEHSTN.Focus()
			End If
		End Sub

		Private Sub cboEHSTT_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboEHSTT.SelectedIndexChanged
			'MsgBox Left(cboEHSTT.List(cboEHSTT.ListIndex), 1)
		End Sub

		Private Sub cboELITN_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboELITN.ClickEvent
			If eventArgs.area = 2 Then
				txtELITN.Text = cboELITN.BoundText
				txtELITD.Text = cboELITN.CtlText
				cboELITN.Visible = False
				txtELQTY.Focus()
			End If
		End Sub

		Private Sub cboELLTN_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboELLTN.ClickEvent
			If eventArgs.area = 2 Then
				txtELLTN.Text = cboELLTN.CtlText
				cboELLTN.Visible = False

			End If
		End Sub

		Private Sub cboELPER_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboELPER.SelectedIndexChanged
			Dim DiscAMT, DiscBAM As Object
			txtELVAT.Text = VATRate(txtEHCNO, txtELITN)

			Select Case cboELPER.SelectedIndex + 1
				Case 1
					txtELBVA.Text = CStr(Val(txtELQTY.Text) * Val(txtELPRC.Text) * Val(txtELVAT.Text))
					txtELBCA.Text = CStr((Val(txtELQTY.Text) * Val(txtELPRC.Text)) + Val(txtELBVA.Text))
					DiscBAM = Val(txtELBCA.Text) * Val(txtELPDC.Text) / 100
					txtELBCA.Text = CStr(Val(txtELBCA.Text) - Val(DiscBAM))

					txtELVAM.Text = CStr(Val(txtELQTY.Text) * Val(txtELPRC.Text) * Val(txtEHCER.Text) * Val(txtELVAT.Text))
					txtELAMT.Text = CStr(Val(txtELQTY.Text) * Val(txtELPRC.Text) * Val(txtEHCER.Text) + Val(txtELVAM.Text))
					DiscAMT = Val(txtELAMT.Text) * Val(DiscAMT) / 100
					txtELAMT.Text = CStr(Val(txtELAMT.Text) - Val(DiscAMT))
				Case 2
					txtELBVA.Text = CStr(Val(txtELWGT.Text) * Val(txtELPRC.Text) * Val(txtELVAT.Text))
					txtELBCA.Text = CStr((Val(txtELWGT.Text) * Val(txtELPRC.Text)) + Val(txtELBVA.Text))
					DiscBAM = Val(txtELBCA.Text) * Val(txtELPDC.Text) / 100
					txtELBCA.Text = CStr(Val(txtELBCA.Text) - Val(DiscBAM))

					txtELVAM.Text = CStr(Val(txtELWGT.Text) * Val(txtELPRC.Text) * Val(txtEHCER.Text) * Val(txtELVAT.Text))
					txtELAMT.Text = CStr(Val(txtELWGT.Text) * Val(txtELPRC.Text) * Val(txtEHCER.Text) + Val(txtELVAM.Text))
					DiscAMT = Val(txtELAMT.Text) * Val(DiscAMT) / 100
					txtELAMT.Text = CStr(Val(txtELAMT.Text) - Val(DiscAMT))
			End Select
			'txtELPDC.SetFocus
		End Sub

		Private Sub cboELWHC_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataListLib.DDataComboEvents_ClickEvent) Handles cboELWHC.ClickEvent
			Dim Havelot As Byte
			If eventArgs.area = 2 Then
				txtELWHC.Text = cboELWHC.BoundText
				txtWMDSC.Text = cboELWHC.CtlText
				cboELWHC.Visible = False
				Havelot = False
				If Find("IIM", "IMLOT", " WHERE IMITN='" & txtELITN.Text & "'") Then Havelot = True
				If Havelot Then
					txtELLTN.Focus()
				Else
					'        txtELQTY.SetFocus
				End If
				' txtTHTTC.SetFocus

			End If
		End Sub

		Private Sub cmdConfirmed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdConfirmed.Click
			Dim recECL As Object
			Dim SQL As Object
			Dim txtELBOD As String
			If Not ValidInput() Then Exit Sub
			'Truong hop da in hay confirm
			If cboEHSTT.SelectedIndex + 1 = 2 Or cboEHSTT.SelectedIndex + 1 = 3 Then 'Package Print Or Comfirmed
				txtELPSQ.Text = IIf(IsNumeric(txtELPSQ.Text), txtELPSQ.Text, 0)
				txtELPSW.Text = IIf(IsNumeric(txtELPSW.Text), txtELPSW.Text, 0)
				If Val(txtELPSQ.Text) > 0 And Val(txtELPSW.Text) > 0 Then
					txtELBOQ.Text = CStr(Val(txtELQTY.Text) - Val(txtELPSQ.Text))
					txtELBOW.Text = CStr(Val(txtELWGT.Text) - Val(txtELPSW.Text))
					txtELBOD = IIf(chkELBOD.CheckState = 1, "Y", "")
					SQL = "Update  ECL set ELPSQ=" & txtELPSQ.Text & ",ELPSW=" & txtELPSW.Text & ",ELWHC='" & txtELWHC.Text & "',ELLTN='" & txtELLTN.Text & "',ELSTT='3' where ELODN='" & txtEHODN.Text & "' " & " AND ELOLN=" & txtELOLN.Text
					DBconn.Execute(SQL)
					WriteToIIM(txtELITN, -Val(txtELBOW.Text), -Val(txtELBOQ.Text))
					SQL = "Update ECH set EHSTT='3'  where EHODN='" & txtEHODN.Text & "' " & " AND (EHSTT='2')"
					DBconn.Execute(SQL)

					If chkELBOD.CheckState = 1 And Val(txtELBOQ.Text) > 0 Then 'Back Order
						SQL = "Update ECL set ELQTY=" & txtELPSQ.Text & ",ELWGT=" & txtELPSW.Text & ",ELSTT='3',ELBOD='" & txtELBOD & "'" & " where ELODN='" & txtEHODN.Text & "' AND ELOLN=" & txtELOLN.Text
						'MsgBox SQL
						DBconn.Execute(SQL)

						recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' order by ELOLN Desc ")
						If recECL.EOF Then
							txtELOLN.Text = CStr(1)
						Else
							txtELOLN.Text = recECL!ELOLN + 1
						End If
						SQL = "Insert into ECL(ELODN,ELITN,ELITD,ELLUS" & ",ELPER,ELOLN,ELSTT " & ",ELQTY,ELWGT,ELPSQ,ELPSW,ELPRC,ELPDC" & ",ELAMT,ELVAM,ELBCA,ELBVA,ELVAT) values " & "('" & txtEHODN.Text & "','" & txtELITN.Text & "','" & txtELITD.Text & "','" & UserLogin & "'" & ",'" & cboELPER.SelectedIndex + 1 & "','" & txtELOLN.Text & "','4'" & "," & txtELBOQ.Text & "," & txtELBOW.Text & ",0,0," & txtELPRC.Text & "," & txtELPDC.Text & "," & txtELAMT.Text & "," & txtELVAM.Text & "," & txtELBCA.Text & "," & txtELBVA.Text & "," & txtELVAT.Text & ")"

						'MsgBox SQL
						DBconn.Execute(SQL)
						WriteToIIM(txtELITN, Val(txtELBOW.Text), Val(txtELBOQ.Text))

					End If
					WriteToScreen()
					If SELECTROW = "" Then SELECTROW = 1
					Adodc4.Recordset.AbsolutePosition = SELECTROW
				Else
					MsgBox("Packed Quantity and Packed Weight must be >0")
				End If
			End If

		End Sub

		Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click
			'VB6_RemoveADODataBinding()
			Me.Close()
		End Sub

		Private Sub cmdPackedSlip_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPackedSlip.Click
			Dim SQL As Object
			On Error GoTo ord540_err
			Adodc4.Recordset.AbsolutePosition = SELECTROW

			CrystalReport1.ReportFileName = DDAN & "\ORD250.rpt"
			CrystalReport1.RetrieveStoredProcParams()
			CrystalReport1.set_StoredProcParam(0, txtEHODN.Text)
			CrystalReport1.set_StoredProcParam(1, "1")
			CrystalReport1.Destination = Crystal.DestinationConstants.crptToWindow
			CrystalReport1.Action = 1
			SQL = "Update ECH set EHSTT='2'  where EHODN='" & txtEHODN.Text & "' " & " AND (EHSTT='B' OR EHSTT='4')"
			DBconn.Execute(SQL)
			SQL = "Update  ECL set ELSTT='2' where ELODN='" & txtEHODN.Text & "' " & " AND (ELSTT='B' OR ELSTT='4')"
			DBconn.Execute(SQL)
			WriteToScreen()
			If SELECTROW = "" Then SELECTROW = 1
ord540_next:
			Exit Sub
ord540_err:
			MsgBox("ORD540_Packingslip Printing" & Err.Description)
			Resume ord540_next
		End Sub



		Private Sub cmdPrintConfirmed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPrintConfirmed.Click
			CrystalReport1.ReportFileName = DDAN & "\ORD260.rpt"
			CrystalReport1.RetrieveStoredProcParams()
			CrystalReport1.set_StoredProcParam(0, txtEHODN.Text)
			CrystalReport1.set_StoredProcParam(1, "2")
			CrystalReport1.Destination = Crystal.DestinationConstants.crptToWindow
			CrystalReport1.Action = 1
		End Sub

		Private Sub cmdReview_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReview.Click
			'Dim myform As New frmReview
			'myform.Tag = "ORD540"
			' myform.Show()
			frmReview.Tag = "ORD540"
			frmReview.ShowDialog()
			ISEDITING = False
			ISADDING = False
			If frmReview.Tag <> "" Then
				txtEHODN.Text = frmReview.Tag
				'If myform.Tag <> "" Then
				'txtEHODN.Text = myform.Tag
				txtELOLN.Text = CStr(1)
				WriteToScreen()
			End If
		End Sub
		Sub WriteToScreen()
			Dim txtELBOD As Object
			Dim i As Object
			Dim recECL As ADODB.Recordset
			cboELITN.Visible = False
			cboELWHC.Visible = False
			cboELLTN.Visible = False

			recECL = DBconn.Execute("Select ECH.* from ECH where ECH.EHODN='" & txtEHODN.Text & "'")
			If Not recECL.EOF Then
				With recECL
					For i = 0 To cboEHITP.Items.Count - 1
						If VB.Left(VB6.GetItemString(cboEHITP, i), 1) = .Fields("EHITP").Value Then
							cboEHITP.SelectedIndex = i
							Exit For
						End If
					Next i
					txtEHNOL.Text = IIf(IsDBNull(.Fields("EHNOL").Value), 0, .Fields("EHNOL").Value)
					txtEHODN.Text = .Fields("EHODN").Value
					OldEHODN = txtEHODN.Text
					txtEHDTE.Text = .Fields("EHDTE").Value
					txtEHCNO.Text = .Fields("EHCNO").Value
					txtEHSTN.Text = .Fields("EHSTN").Value
					txtEHSTA.Text = .Fields("EHSTA").Value
					txtCMNME.Text = Find("RCM", "CMNME", " WHERE CMCNO='" & txtEHCNO.Text & "'")
					txtEHCPO.Text = IIf(IsDBNull(.Fields("EHCPO").Value), 0, .Fields("EHCPO").Value)
					txtEHPTC.Text = IIf(IsDBNull(.Fields("EHPTC").Value), "", .Fields("EHPTC").Value)
					For i = 0 To cboEHSTT.Items.Count - 1
						If VB.Left(VB6.GetItemString(cboEHSTT, i), 1) = .Fields("EHSTT").Value Then
							cboEHSTT.SelectedIndex = i
							Exit For
						End If
					Next i
					cboEHCCD.defText = .Fields("EHCCD").Value
					txtEHCER.Text = .Fields("EHCER").Value
					OldCurRate = CDbl(txtEHCER.Text)
					txtEHCCD.Text = .Fields("EHCCD").Value
					txtEHSNO.Text = .Fields("EHSNO").Value
					txtMMNME.Text = Find("SMM", "MMNME", " WHERE MMSNO='" & txtEHSNO.Text & "'")
					txtEHDUE.Text = .Fields("EHDUE").Value
					txtEHAMT.Text = .Fields("EHAMT").Value
					txtEHVAM.Text = .Fields("EHVAM").Value
					txtEHBCA.Text = .Fields("EHBAM").Value
					txtEHBVA.Text = .Fields("EHBVA").Value

					.Close()
				End With
			End If

			If txtELOLN.Text <> "" Then
				recECL = DBconn.Execute("Select ECL.* from ECL where ECL.ELODN='" & txtEHODN.Text & "' and ELOLN='" & txtELOLN.Text & "'")
				If Not recECL.EOF Then
					With recECL
						txtELITN.Text = .Fields("ELITN").Value
						txtELITD.Text = .Fields("ELITD").Value
						txtELWHC.Text = IIf(IsDBNull(.Fields("ELWHC").Value), "", .Fields("ELWHC").Value)
						txtWMDSC.Text = Find("IWM", "WMDSC", " WHERE WMWHC='" & txtELWHC.Text & "'")
						txtELLTN.Text = IIf(IsDBNull(.Fields("ELLTN").Value), "", .Fields("ELLTN").Value)
						txtELOLN.Text = .Fields("ELOLN").Value
						txtELQTY.Text = .Fields("ELQTY").Value
						txtELPSQ.Text = IIf(IsDBNull(.Fields("ELPSQ").Value), 0, .Fields("ELPSQ").Value)
						txtELWGT.Text = .Fields("ELWGT").Value
						txtELPSW.Text = IIf(IsDBNull(.Fields("ELPSW").Value), 0, .Fields("ELPSW").Value)
						txtELPRC.Text = .Fields("ELPRC").Value
						For i = 0 To cboELPER.Items.Count - 1
							If VB.Left(VB6.GetItemString(cboELPER, i), 1) = .Fields("ELPER").Value Then
								cboELPER.SelectedIndex = i
								Exit For
							End If
						Next i
						txtELPDC.Text = .Fields("ELPDC").Value
						txtELAMT.Text = .Fields("ELAMT").Value ' Line amount
						txtELVAM.Text = .Fields("ELVAM").Value ' VAT line (VND)
						txtELBCA.Text = .Fields("ELBCA").Value ' Base currency line amount
						txtELBVA.Text = .Fields("ELBVA").Value ' VAT base currency
						txtELVAT.Text = .Fields("ELVAT").Value
						For i = 0 To cboELSTT.Items.Count - 1
							If VB.Left(VB6.GetItemString(cboELSTT, i), 1) = .Fields("ELSTT").Value Then
								cboELSTT.SelectedIndex = i
								Exit For
							End If
						Next i
						txtELBOD = IIf(IsDBNull(.Fields("ELBOD").Value), "", .Fields("ELBOD").Value)
						chkELBOD.CheckState = IIf(txtELBOD = "Y", 1, 0)
						.Close()
					End With
				End If
			End If


			Adodc4.RecordSource = "Select ECL.*,ECH.* from ECL " & " LEFT JOIN ECH ON ECL.ELODN=ECH.EHODN where ECH.EHODN ='" & txtEHODN.Text & "' ORDER BY ELOLN"
			Adodc4.Refresh()

			txtELPSQ.ReadOnly = (VB.Left(VB6.GetItemString(cboELSTT, i), 1) = "6")
			txtELPSW.ReadOnly = (VB.Left(VB6.GetItemString(cboELSTT, i), 1) = "6")
			txtELWHC.ReadOnly = (VB.Left(VB6.GetItemString(cboELSTT, i), 1) = "6")
			txtELLTN.ReadOnly = (VB.Left(VB6.GetItemString(cboELSTT, i), 1) = "6")
			chkELBOD.Enabled = Not (VB.Left(VB6.GetItemString(cboELSTT, i), 1) = "6")



		End Sub
		Private Sub frmORD540_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
			VB6_RemoveADODataBinding()
		End Sub
		Private Sub frmORD540_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
			NewTrans = False
			ISEDITING = False
			ISADDING = False
			OpenFile()
			ButtonStatus()
			VB6_AddADODataBinding()
			cboEHCNO.RowSource = ADOBind_Adodc1.DataSource
			cboEHSNO.RowSource = ADOBind_Adodc7.DataSource
			cboEHCCD.RowSource = ADOBind_Adodc5.DataSource
			cboELITN.RowSource = ADOBind_Adodc3.DataSource
			cboELWHC.RowSource = ADOBind_Adodc8.DataSource
			'cboELLTN.RowSource = ADOBind_Adodc9.DataSource
			Dim myDataCaptions As String() = {"Line", "Item", "Item Description", "Quantity", "Packed QTY", "Weight", "Packed WGT", "Unit price", "Price per", "Line amount", "Base Cur Amount", "Status"}
			Dim myDataFields As String() = {"ELOLN", "ELITN", "ELITD", "ELQTY", "ELPSQ", "ELWGT", "ELPSW", "ELPRC", "ELPER", "ELAMT", "ELBCA", "ELSTT"}
			setDataGridView(myDataCaptions, myDataFields, Me.grdECL)
		End Sub

		Private Sub grdECL_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles grdECL.ClickEvent
			If Adodc4.Recordset.RecordCount = 0 Then
				Exit Sub
			End If
			txtELOLN.Text = grdECL.Columns(1).value

			WriteToScreen()
			If SELECTROW = "" Then SELECTROW = 1
			Adodc4.Recordset.AbsolutePosition = SELECTROW
		End Sub



		Private Sub grdECL_RowColChange(ByVal eventSender As System.Object, ByVal eventArgs As AxMSDataGridLib.DDataGridEvents_RowColChangeEvent) Handles grdECL.RowColChange
			SELECTROW = Adodc4.Recordset.Bookmark
		End Sub

		Private Sub txtEHCCD_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCCD.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As String
			Dim RecCCI As ADODB.Recordset
			If KeyAscii = 13 Then
				Result = Find("CCM", "CMCCD", "WHERE CMCCD='" & txtEHCCD.Text & "'")
				If Result <> "" Then
					RecCCI = DBconn.Execute("Select * from CCI where CICCD='" & txtEHCCD.Text & "' order by CIDTE DESC")
					If Not RecCCI.EOF Then
						txtEHCER.Text = RecCCI.Fields("CICCR").Value
					Else
						txtEHCER.Text = CStr(0)
					End If
					txtEHCER.Focus()
				Else
					cboEHCCD.Visible = True
					cboEHCCD.Focus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHCER_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCER.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELITN.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHCNO_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCNO.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As String
			If KeyAscii = 13 Then
				Result = Find("RCM", "CMNME", "WHERE CMCNO='" & txtEHCNO.Text & "'")
				If Result = "" Then
					cboEHCNO.Visible = True
					cboEHCNO.Focus()
				Else
					cboEHCNO.Visible = False
					txtCMNME.Text = Result
					txtEHSNO.Focus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHCPO_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHCPO.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHCCD.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHDTE_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHDTE.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHCNO.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHDUE_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHDUE.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHCPO.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHODN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHODN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As Object
			If KeyAscii = 13 Then
				Result = Find("ECH", "EHODN", "WHERE EHODN='" & txtEHODN.Text & "'")
				If Result = "" Then
					txtEHDTE.Focus()
				Else
					MsgBox("Order Number is already exist")
					txtEHODN.Focus()
					GoTo EventExitSub
				End If
			End If
EventExitSub:
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHSNO_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHSNO.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)

			Dim Result As String
			If KeyAscii = 13 Then
				Result = Find("SMM", "MMNME", "WHERE MMSNO='" & txtEHSNO.Text & "'")
				If Result = "" Then
					cboEHSNO.Visible = True
					cboEHSNO.Focus()
				Else
					cboEHSNO.Visible = False
					txtMMNME.Text = Result
					txtEHSTN.Focus()
				End If
			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHSTA_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHSTA.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHDUE.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtEHSTN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtEHSTN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtEHSTA.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELAMT_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELAMT.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELVAM.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELBCA_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELBCA.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELBVA.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELBVA_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELBVA.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELAMT.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELITN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELITN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As String
			If KeyAscii = 13 Then
				Result = Find("IIM", "IMITD", "WHERE IMITN='" & txtELITN.Text & "'")
				If Result = "" Then
					cboELITN.Visible = True
					cboELITN.Focus()
				Else
					txtELITD.Text = Result
					cboELITN.Visible = False
					txtELQTY.Focus()
				End If

			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub
		Sub OpenFile()
			Dim SQL As Object
			Dim DelStatus As Object
			Dim FieldDel As Object
			Adodc1.ConnectionString = ConnectString
			Adodc1.ConnectionTimeout = 10
			Adodc1.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc1.RecordSource = "Select * from RCM"
			Adodc1.Refresh()

			Adodc2.ConnectionString = ConnectString
			Adodc2.ConnectionTimeout = 10
			Adodc2.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc2.RecordSource = "Select * from AVM"
			Adodc2.Refresh()

			FieldDel = "IMRID"
			DelStatus = "IZ"
			SQL = "Select * from IIM where " & FieldDel & " <>'" & DelStatus & "' "
			Adodc3.ConnectionString = ConnectString
			Adodc3.ConnectionTimeout = 10
			Adodc3.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc3.RecordSource = SQL
			Adodc3.Refresh()

			Adodc4.ConnectionString = ConnectString
			Adodc4.ConnectionTimeout = 10
			Adodc4.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc4.RecordSource = "Select ECL.*,ECH.* from ECL " & " LEFT JOIN ECH ON ECL.ELODN=ECH.EHODN where ECH.EHODN ='" & txtEHODN.Text & "' and ELSTT<>'7' ORDER BY ELOLN"
			Adodc4.Refresh()

			Adodc5.ConnectionString = ConnectString
			Adodc5.ConnectionTimeout = 10
			Adodc5.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc5.RecordSource = "Select * from CCM"
			Adodc5.Refresh()

			Adodc6.ConnectionString = ConnectString
			Adodc6.ConnectionTimeout = 10
			Adodc6.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc6.RecordSource = "Select * from ECH"
			Adodc6.Refresh()

			Adodc7.ConnectionString = ConnectString
			Adodc7.ConnectionTimeout = 10
			Adodc7.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc7.RecordSource = "Select * from SMM"
			Adodc7.Refresh()

			Adodc8.ConnectionString = ConnectString
			Adodc8.ConnectionTimeout = 10
			Adodc8.CommandType = ADODB.CommandTypeEnum.adCmdText
			Adodc8.RecordSource = "Select * from IWM"
			Adodc8.Refresh()
			' Create array from combobox Custtype,StatusOrder, ValuePer
			INVType(1) = "1 Normal"
			INVType(2) = "2 By pass Inventory"

			StaOrd(1) = "1 New"
			StaOrd(2) = "2 Printed"
			StaOrd(3) = "3 Confirmed"
			StaOrd(4) = "4 B/O"
			StaOrd(5) = "5 Caredit hold"
			StaOrd(6) = "6 Completed"
			StaOrd(7) = "7 Canceled"
			Per(1) = "Unt"
			Per(2) = "Wgt"
			Per(3) = "All"
		End Sub

		Sub ButtonStatus()
			'cmdAddNew.Enabled = Not ISEDITING
			'cmdReview.Enabled = Not ISEDITING
			'cmdNewItem.Enabled = Not ISEDITING
			'cmdEdit.Enabled = Not ISEDITING
			'cmdSave.Enabled = ISEDITING
			'cmdCancel.Enabled = ISEDITING
			FrameBB.Enabled = ISEDITING	'NewTrans
			FrameECLine.Enabled = ISEDITING
			'txtEHODN.Locked = Not ISADDING
		End Sub

		Sub WriteToFile()
			Dim txtEHBAM As Object
			Dim Unt As Object
			Dim WGT As Object
			Dim txtEHLDT As Object
			Dim SQL As Object
			Dim txtELLDT As Object
			Dim recECL As ADODB.Recordset
			txtELLDT = VB6.Format(Now, "yyyy-mm-dd hh:mm:ss")
			If ISADDING Then
				If txtELITN.Text <> "" Then
					recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' order by ELOLN Desc ")
					If recECL.EOF Then
						txtELOLN.Text = CStr(1)
					Else
						txtELOLN.Text = recECL.Fields("ELOLN").Value + 1
					End If
					SQL = "Insert into ECL(ELODN,ELITN,ELITD,ELWHC,ELLTN,ELLUS" & ",ELPER,ELOLN,ELSTT " & ",ELQTY,ELWGT,ELPRC,ELPDC" & ",ELAMT,ELVAM,ELBCA,ELBVA,ELVAT) values " & "('" & txtEHODN.Text & "','" & txtELITN.Text & "','" & txtELITD.Text & "','" & txtELWHC.Text & "','" & txtELLTN.Text & "','" & UserLogin & "'" & ",'" & cboELPER.SelectedIndex + 1 & "','" & txtELOLN.Text & "','1'" & "," & txtELQTY.Text & "," & txtELWGT.Text & "," & txtELPRC.Text & "," & txtELPDC.Text & "," & txtELAMT.Text & "," & txtELVAM.Text & "," & txtELBCA.Text & "," & txtELBVA.Text & "," & txtELVAT.Text & ")"

					'MsgBox SQL
					DBconn.Execute(SQL)
					WriteToIIM(txtELITN, Val(txtELWGT.Text), Val(txtELQTY.Text))
				End If
			Else
				txtEHLDT = VB6.Format(Now, "yyyy-mm-dd hh:mm:ss")
				txtEHDTE.Text = VB6.Format(txtEHDTE.Text, "yyyy-mm-dd hh:mm:ss")
				txtEHDUE.Text = VB6.Format(txtEHDUE.Text, "yyyy-mm-dd hh:mm:ss")
				If VB.Left(VB6.GetItemString(cboEHSTT, cboEHSTT.SelectedIndex), 1) = "7" Then 'Cancel

					recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' AND ELSTT<>'7'")
					With recECL
						Do While Not recECL.EOF
							WGT = -(.Fields("ELWGT")).Value
							Unt = -(.Fields("ELQTY")).Value
							WriteToIIM(.Fields("ELITN"), WGT, Unt)
							recECL.MoveNext()
						Loop
					End With
					SQL = "Update ECL  set ELSTT='7' where ELODN='" & txtEHODN.Text & "'"
					DBconn.Execute(SQL)
				Else
					recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' and ELOLN='" & txtELOLN.Text & "'")
					With recECL
						If VB.Left(VB6.GetItemString(cboELSTT, cboELSTT.SelectedIndex), 1) = "7" Then 'Cancel
							Unt = -(.Fields("ELQTY")).Value
							WGT = -(.Fields("ELWGT")).Value
						Else
							Unt = Val(txtELQTY.Text) - .Fields("ELQTY").Value
							WGT = Val(txtELWGT.Text) - .Fields("ELWGT").Value
						End If
					End With
					WriteToIIM(txtELITN, WGT, Unt)
				End If
				SQL = "Update ECL set ELLDT='" & txtELLDT & "',ELITN='" & txtELITN.Text & "',ELITD='" & txtELITD.Text & "'" & ",ELWHC='" & txtELWHC.Text & "',ELLTN='" & txtELLTN.Text & "',ELLUS='" & UserLogin & "'" & ",ELPER='" & cboELPER.SelectedIndex + 1 & "',ELOLN='" & txtELOLN.Text & "',ELSTT='" & cboELSTT.SelectedIndex + 1 & "'" & ",ELQTY=" & txtELQTY.Text & ",ELWGT=" & txtELWGT.Text & ",ELPRC=" & txtELPRC.Text & ",ELPDC=" & txtELPDC.Text & ",ELAMT=" & txtELAMT.Text & ",ELVAM=" & txtELVAM.Text & ",ELBCA=" & txtELBCA.Text & ",ELBVA=" & txtELBVA.Text & ",ELVAT=" & txtELBVA.Text & " where ELODN='" & OldEHODN & "' AND ELOLN='" & txtELOLN.Text & "'"
				DBconn.Execute(SQL)


				SQL = "Update ECH set EHLDT='" & txtEHLDT & "',EHDTE='" & txtEHDTE.Text & "',EHITP='" & cboEHITP.SelectedIndex + 1 & "'" & ",EHODN='" & txtEHODN.Text & "',EHCNO='" & txtEHCNO.Text & "',EHSTN='" & txtEHSTN.Text & "',EHPTC='" & txtEHPTC.Text & "'" & ",EHSTA='" & txtEHSTA.Text & "',EHSNO='" & txtEHSNO.Text & "',EHDUE='" & txtEHDUE.Text & "',EHCPO='" & txtEHCPO.Text & "'" & ",EHCCD='" & txtEHCCD.Text & "',EHCER=" & txtEHCER.Text & " where EHODN='" & OldEHODN & "'"
				DBconn.Execute(SQL)
			End If
			Dim RecCountLine As ADODB.Recordset
			RecCountLine = DBconn.Execute("SELECT ELODN, COUNT(ELOLN) AS CountLine From ECL " & " WHERE (ELODN = '" & txtEHODN.Text & "') AND (ELSTT <> N'7')GROUP BY ELODN")
			txtEHNOL.Text = RecCountLine.Fields("CountLine").Value
			RecCountLine.Close()
			If NewTrans Then
				txtEHLDT = VB6.Format(Now, "yyyy-mm-dd hh:mm:ss")
				txtEHDTE.Text = VB6.Format(WorkingDate, "yyyy-mm-dd hh:mm:ss")
				txtEHDUE.Text = VB6.Format(txtEHDUE.Text, "yyyy-mm-dd hh:mm:ss")

				SQL = "Insert into ECH (EHLDT,EHDTE,EHITP" & ",EHODN,EHCNO,EHSTN,EHPTC" & ",EHSTA,EHSNO,EHDUE,EHCPO" & ",EHCCD,EHCER,EHNOL,EHSTT) values " & "('" & txtEHLDT & "','" & txtEHDTE.Text & "','" & cboEHITP.SelectedIndex + 1 & "'" & ",'" & txtEHODN.Text & "','" & txtEHCNO.Text & "','" & txtEHSTN.Text & "','" & txtEHPTC.Text & "'" & ",'" & txtEHSTA.Text & "','" & txtEHSNO.Text & "','" & txtEHDUE.Text & "','" & txtEHCPO.Text & "'" & ",'" & txtEHCCD.Text & "'," & txtEHCER.Text & "," & txtEHNOL.Text & ",'1')"
				MsgBox(SQL)
				DBconn.Execute(SQL)

			End If

			recECL.Close()
			recECL = DBconn.Execute("SELECT ELODN, SUM(ELVAM) AS SumELVAM, SUM(ELAMT)" & " AS SumELAMT, SUM(ELBVA) AS SumELBVA, SUM(ELBCA) " & " AS SumELBCA FROM ECL WHERE (ELODN = '" & txtEHODN.Text & "') GROUP BY ELODN")
			With recECL
				txtEHAMT.Text = .Fields("SumELAMT").Value
				txtEHVAM.Text = .Fields("SumELVAM").Value
				txtEHBAM = .Fields("SumELBCA").Value
				txtEHBVA.Text = .Fields("SumELBVA").Value
			End With
			recECL.Close()

			DBconn.Execute("UPDATE ECH SET EHAMT=" & txtEHAMT.Text & ",EHVAM=" & txtEHVAM.Text & ",EHBAM=" & txtEHBAM & ",EHBVA=" & txtEHBVA.Text & " WHERE EHODN='" & txtEHODN.Text & "'")

			Adodc4.RecordSource = "Select ECL.*,ECH.* from ECL " & " LEFT JOIN ECH ON ECL.ELODN=ECH.EHODN where ECH.EHODN ='" & txtEHODN.Text & "' ORDER BY ELOLN"
			Adodc4.Refresh()

		End Sub

		Sub WriteToIIM(ByRef ITN As Object, ByRef WGT As Object, ByRef unit As Object)
			Dim SQL As Object

			unit = IIf(IsNumeric(unit), unit, 0)
			WGT = IIf(IsNumeric(WGT), WGT, 0)


			SQL = "UPDATE IIM SET IMCOW=IMCOW+" & WGT & ",IMCOU=IMCOU+" & unit & " WHERE IMITN='" & ITN & "'"
			DBconn.Execute(SQL)

		End Sub


		Private Sub txtELLTN_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtELLTN.Enter
			Dim Response As Object
			Dim Result As Object
			Dim Havelot As Byte
			Havelot = False
			If Find("IIM", "IMLOT", " WHERE IMITN='" & txtELITN.Text & "'") Then Havelot = True
			If Havelot Then
				If txtELITN.Text <> "" And txtELWHC.Text <> "" Then
					Result = Find("ILI", "ILLOT", " WHERE  ILITN='" & txtELITN.Text & "' AND  ILWHC='" & txtELWHC.Text & "'")
					If Result <> "" Then
						Adodc9.ConnectionString = ConnectString
						Adodc9.ConnectionTimeout = 10
						Adodc9.CommandType = ADODB.CommandTypeEnum.adCmdText
						Adodc9.RecordSource = "Select * from ILI WHERE ILITN='" & txtELITN.Text & "' AND  ILWHC='" & txtELWHC.Text & "'"
						Adodc9.Refresh()
					Else
						Response = MsgBox("There are no lot of this Item in this Warehouse.Do you want to add new lot?", MsgBoxStyle.YesNo + MsgBoxStyle.Critical + MsgBoxStyle.DefaultButton2, "Chu y'")
						If Response = MsgBoxResult.Yes Then
							Dim myform As New frmINV120
							myform.Show()
							'frmINV120/.ShowDialog()
						Else
							MsgBox("Please select another Warehouse!")
							txtELWHC.Focus()
						End If
					End If
				Else
					MsgBox("Please select an Item and Warehouse fisrt!")
				End If
			Else
				MsgBox("This Item have no lot")
				txtELPSQ.Focus()
			End If
		End Sub

		Private Sub txtELLTN_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELLTN.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As Object
			If KeyAscii = 13 Then
				Result = Find("ILI", "ILLOT", " WHERE  ILITN='" & txtELITN.Text & "' AND  ILWHC='" & txtELWHC.Text & "' AND ILLOT='" & txtELLTN.Text & "'")
				If Result = "" Then
					cboELLTN.Visible = True
					cboELLTN.Focus()
				Else
					txtELQTY.Focus()
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELPDC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELPDC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELVAT.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELPRC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELPRC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then cboELPER.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELQTY_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELQTY.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELWGT.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELVAM_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELVAM.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim cmdSave As Object
			If KeyAscii = 13 Then cmdSave.SetFocus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELVAT_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELVAT.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELBCA.Focus()
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub

		Private Sub txtELWGT_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELWGT.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = 13 Then txtELPRC.Focus()

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub
		Sub tam()
			Dim Unt As Object
			Dim WGT As Object
			Dim recECL As Object
			Dim SQL As Object
			If VB.Left(VB6.GetItemString(cboEHSTT, cboEHSTT.SelectedIndex), 1) = "7" Then 'Cancel
				SQL = "Update ECL  set ELSTT='7' where ELODN='" & txtEHODN.Text & "'"
				DBconn.Execute(SQL)

				recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "'")
				With recECL
					Do While Not recECL.EOF
						WGT = -(!ELWGT)
						Unt = -(!ELQTY)
						WriteToIIM(!ELITN, WGT, Unt)
						recECL.MoveNext()
					Loop
				End With
			Else
				recECL = DBconn.Execute("Select * from ECL where ELODN='" & txtEHODN.Text & "' and ELOLN='" & txtELOLN.Text & "'")
				With recECL
					If VB.Left(VB6.GetItemString(cboELSTT, cboELSTT.SelectedIndex), 1) = "7" Then 'Cancel
						Unt = -(recECL!ELQTY)
						WGT = -(recECL!ELWGT)
					Else
						Unt = recECL!ELQTY - Val(txtELQTY.Text)
						WGT = recECL!ELWGT - Val(txtELWGT.Text)
					End If
				End With
				WriteToIIM(txtELITN, WGT, Unt)
			End If
		End Sub

		Function ValidInput() As Object
			Dim Result As Object
			Dim StrErr As String
			Dim Havelot As Boolean
			Havelot = False
			If Find("IIM", "IMLOT", " WHERE IMITN='" & txtELITN.Text & "'") <> "" Then Havelot = True
			If Find("IIM", "IMITN", " WHERE IMITN='" & txtELITN.Text & "'") <> "" Then
				If Find("IWM", "WMWHC", " WHERE WMWHC='" & txtELWHC.Text & "'") <> "" Then
					If Havelot Then
						If Find("ILI", "ILLOT", " WHERE  ILITN='" & txtELITN.Text & "' AND  ILWHC='" & txtELWHC.Text & "'") = "" Then
							StrErr = StrErr & Chr(13) & "* Can't find this Lot  of  this Item in this Warehouse"
						End If
					End If
				Else
					StrErr = StrErr & Chr(13) & "* Can't find this Warehouse"
				End If
			Else
				StrErr = StrErr & Chr(13) & "* Can't find this Item"
			End If
			If txtELQTY.Text.Length = 0 Then
				ValidInput = False
				Exit Function
			End If
			If CDbl(txtELQTY.Text) = 0 Then StrErr = StrErr & Chr(13) & "* Quantity must be >0"
			If txtELWGT.Text.Length = 0 Then
				ValidInput = False
				Exit Function
			End If
			If CDbl(txtELWGT.Text) = 0 Then StrErr = StrErr & Chr(13) & "* Weight must be >0"
			If StrErr <> "" Then
				MsgBox("Please check again!" & StrErr)
				ValidInput = False
			Else
				ValidInput = True
			End If
		End Function
		Private Sub txtELWHC_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtELWHC.KeyPress
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			Dim Result As String
			Dim Havelot As Byte
			If KeyAscii = 13 Then
				Result = Find("IWM", "WMDSC", "WHERE WMWHC='" & txtELWHC.Text & "'")
				If Result = "" Then
					cboELWHC.Visible = True
					cboELWHC.Focus()
				Else
					txtWMDSC.Text = Result
					cboELWHC.Visible = False
					Havelot = False
					If Find("IIM", "IMLOT", " WHERE IMITN='" & txtELITN.Text & "'") Then Havelot = True
					If Havelot Then
						txtELLTN.Focus()
					Else
						'                 txtELWGT.SetFocus
					End If
				End If
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		End Sub
	End Class
End Namespace